/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javaseapp - Ex2
 * <p>Powered by webrx On 2021-08-25 08:45:25
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Ex2 {
    public static void main(String[] args) {
        var ex = new Ex1();
        //第一线程
        new Thread(() -> {
            String tn = Thread.currentThread().getName();
            System.out.println(tn + ":线程启动");
            while (true) {
                try {
                    ex.add();
                    TimeUnit.SECONDS.sleep(1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "t1").start();

        new Thread(() -> {
            String tn = Thread.currentThread().getName();
            System.out.println(tn + ":线程启动");
            while (true) {
                if (ex.check()) {
                    System.out.println("容器中已经有五个元素了");
                    break;
                }
            }
        }, "t2").start();
    }
}
